<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
             margin: 0%;
             padding: 0%;
        }
        .ad{
            position: relative;
            width: 400px;
            height: 400px;
            background-color: pink;
            margin: 100px auto;
            
        }
        .ad .close{
            position: absolute;
            width: 30px;
            height: 50px;
            border: 1px solid red;
            font-size: 36px;
        }
    </style>
</head>
<body>
    <div class="ad">1</div>
    <div class="ad">2
        <h3 class="close">x</h3>
        <h3 class="cloes2">y</h3>
        <h3 class="close3">z</h3>
    </div>
    <script>
        const a1 = document.querySelector('.ad1');
        const son  = a1.nextElementSibling.children;
        console.log(son[0]);
        const clo = document.querySelector('.close');
        clo.addEventListener('click',function(){
            //事件处理
            const ad = document.querySelector('.ad');
            ad.style.display = 'none';
        },false);
        //const ad = document.querySelector('.ad');
        console.log(clo.parentNode);
        console.log(clo.parentElement);

        const ad = document.querySelectorAll('.ad');
        console.log(ad[0].childNodes);
         console.log(ad[0].children);

         console.log(ad[1].childNodes);
         console.log(ad[1].children);
         console.log('--------------');
         const clo2 = document.querySelector('.close3');
  
  </script>


<button>创建节点</button>
<script>
    const btn = document.querySelector('button');
    btn.addEventListener('click',function(){
        // 点击按钮创建节点并显示到网页中
        const box = document.createElement('div');
        box.innerHTML = "这是新创的box";
        // 向当前节点的各个节点追加一个div(box)
        btn.previousSibling.appendChild(box);
    })
</script>
</body>
</html>